package com.wms.common.model;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

public class JSONDataTable {
	public final static String SORT_DIR="asc";
	
	private int recordsReturned;
	private int totalRecords=0;
	private int startIndex=0;
	private String sort;
	private String dir = SORT_DIR;
	private int rowsPerPage=15;
	private List records;
	private String successMsg;
	private String errorMsg;
	
	public String getSuccessMsg() {
		return successMsg;
	}

	public void setSuccessMsg(String successMsg) {
		this.successMsg = successMsg;
	}

	public String getErrorMsg() {
		return errorMsg;
	}

	public void setErrorMsg(String errorMsg) {
		this.errorMsg = errorMsg;
	}

	public JSONDataTable(){}
	
	public JSONDataTable(HttpServletRequest request){
		sort = request.getParameter("sort");
		if(sort.equals("STATUS")){
			sort="cpuUtil";
		}
		dir = request.getParameter("dir");	
		String temp = request.getParameter("startIndex");
		if(null != temp && !"".equals(temp)){
			startIndex = Integer.parseInt(temp);
		}else{
			startIndex = 0;
		}
		temp = request.getParameter("results");
		if(null != temp && !"".equals(temp)){
			rowsPerPage = Integer.parseInt(temp);
		}else{
			rowsPerPage = 0;
		}

	}
	
	public void setupJSONDataTable(List data, int totalSize){
		this.setRecords(data);
		this.setRecordsReturned(data.size());
		this.setTotalRecords(totalSize);
	}

	public int getRecordsReturned() {
		return recordsReturned;
	}

	public void setRecordsReturned(int recordsReturned) {
		this.recordsReturned = recordsReturned;
	}

	public int getTotalRecords() {
		return totalRecords;
	}

	public void setTotalRecords(int totalRecords) {
		this.totalRecords = totalRecords;
	}

	public int getStartIndex() {
		return startIndex;
	}

	public void setStartIndex(int startIndex) {
		this.startIndex = startIndex;
	}

	public String getSort() {
		return sort;
	}

	public void setSort(String sort) {
		this.sort = sort;
	}

	public String getDir() {
		return dir;
	}

	public void setDir(String dir) {
		this.dir = dir;
	}

	public List getRecords() {
		return records;
	}

	public void setRecords(List records) {
		this.records = records;
	}

	public int getRowsPerPage() {
		return rowsPerPage;
	}

	public void setRowsPerPage(int rowsPerPage) {
		this.rowsPerPage = rowsPerPage;
	}	

}
